#!/bin/bash
# ============================================================
# Script Name:    peripheralBringup.sh
# Description:    根据ROS参数动态启动不同类型的外围设备控制
#                 支持滚筒、升降机、货叉、液压顶升等多种设备类型
# Author:         haibo
# Created Date:   2025-07-24
# Version:        1.0
# Modified Date:  2025-09-9
# Modified By:    haibo
# Modification:   初始版本
# Usage:          ./peripheralBringup.sh [日志文件路径]
# Notes:          1. 依赖ROS参数服务器中的外围设备配置
#                 2. 支持测试模式检测和启动
#                 3. 需要common.sh公共函数库支持
# ============================================================
source ${HOME}/lgimRobot/bin/common "$@"

main() {
    local device_type=$(get_ros2_param "agv_peripheral_controller.StartupType.value")
    [[ -z "$device_type" ]] && { 
        log "ERROR" "未定义外围设备类型" 
        return 1 
    }
    
    case "$device_type" in
        "jacking_rotary")
            launch_node "agv_peripheral_controller" ros2 run agv_peripheral_controller agv_peripheral_controller_node ;;
        "roller") 
            launch_node "滚筒设备" ros2 run agv_peripheral_controller roller_node ;;
        "fork") 
            launch_node "货叉设备" ros2 run agv_peripheral_controller fork_node ;;
        "lift") 
            launch_node "升降机" ros2 run agv_peripheral_controller lift_node ;;
        "hydraulic_jacking") 
            launch_node "液压顶升" ros2 run agv_peripheral_controller hydraulic_jacking_node ;;
        *) 
            log "ERROR" "未知设备类型: $device_type" 
            return 2 ;;
    esac
    
    # 测试模式
    [ "$(get_ros2_param "agv_peripheral_controller.TestMode.value")" = "true" ] && \
        launch_node "测试模式" ros2 run agv_peripheral_controller test_node
    
    return 0
}

main